﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL;
namespace MyCommon
{
   public class GetTable
    {
       static DataTable dt;
       /// <summary>
       /// get table by  users's option
       /// </summary>
       /// <param name="name"></param>
       /// <returns></returns>
       #region Get table by all      
       public static DataTable Table(string name)
       {
           dt = new DataTable();
           try
           {
               SqlCommand cmd = new SqlCommand("sp_Getall_Option", Connect.Connected());         
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@Name_Table", name)); 

               SqlDataAdapter da = new SqlDataAdapter(cmd);
               da.Fill(dt);
               
           }
           catch
           {
               
           }
           return dt;
       }
       #endregion

       #region Get table by Id
       public static DataTable Table(string nametable, string id)
       {
           dt = new DataTable();
           try
           {
               SqlCommand cmd = new SqlCommand("sp_GetTable_ID", Connect.Connected());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@Name_Table", nametable));
               cmd.Parameters.Add(new SqlParameter("@Id", id));
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               da.Fill(dt);
           }
           catch
           {

           }
           return dt;
       }
       #endregion

       #region Get table by Top
       /// <summary>
       /// Lay len table theo top
       /// </summary>
       /// <param name="nametable"></param>
       /// <param name="top"></param>
       /// <param name="where"></param>
       /// <param name="order"></param>
       /// <returns></returns>
       public static DataTable Table(string nametable, string top,string where,string order)
       {
           dt = new DataTable();
           try
           {
               SqlCommand cmd = new SqlCommand("sp_GetByTop", Connect.Connected());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@Name_Table", nametable));
               cmd.Parameters.Add(new SqlParameter("@Top", top));
               cmd.Parameters.Add(new SqlParameter("@Where", where));
               cmd.Parameters.Add(new SqlParameter("@Order", order));
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               da.Fill(dt);
           }
           catch
           {

           }
           return dt;
       }
       #endregion
    }
}
